﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DalFactory;
using IBLL;
using IDAL;

namespace BLL
{
	public abstract class baseStaticService<T> : IbaseService<T> where T : class, new()
	{
		public IdbSession CurrentDbSession
		{
			get
			{
				return new dbSessionStatic();
			}
		}
		public baseStaticService()
		{
			setDal();
		}
		public abstract void setDal();
		public IBaseDAL<T> dal { get; set; }
		public IQueryable<T> LoadEntities(System.Linq.Expressions.Expression<Func<T, bool>> whereLambda)
		{
			return dal.LoadEntities(whereLambda);
		}

		public T AddDonator(T entity)
		{
			return dal.AddDonator(entity);
		}

		public bool DeleteEntity(T entity)
		{
			dal.DeleteEntity(entity);
			return CurrentDbSession.allSaveChangge();
		}

		public IQueryable<T> LoadPageEntities<s>(int pageIndex, int pageSize, out int totalCount, System.Linq.Expressions.Expression<Func<T, bool>> whereLambda, System.Linq.Expressions.Expression<Func<T, s>> orderbyLambda, bool isAsc)
		{
			return dal.LoadPageEntities<s>(pageIndex, pageSize, out totalCount, whereLambda, orderbyLambda, isAsc);
		}

		public bool UpdateEntity(T entity)
		{
			dal.UpdateEntity(entity);
			return CurrentDbSession.allSaveChangge();
		}
	}
}
